<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>生成器函数参数</title>
  </head>
  <body>
    <script>
      function* gen(arg) {
        console.log(arg); // AAA
        let one = yield 111;
        console.log(one); //BBB
        let two = yield 222;
        console.log(two); // CCC
        let three = yield 333;
        console.log(three); // DDD
      }

      // 执行获取迭代器对象
      let iteratir = gen("AAA");
      // next方法可以传入实参
      console.log(iteratir.next()); //{value: 111, done: false}
      // 在第二次调用next方法传递的实参，会作为第一个yield表达式的值
      console.log(iteratir.next('BBB')); 
      console.log(iteratir.next('CCC'));
      console.log(iteratir.next('DDD')); //{value: undefined, done: true}
    </script>
  </body>
</html>
